package LeetCode.leetcode;

/**
 * @author: leiwenkang
 * @date: 2020/7/11
 * @time: 23:44
 */
public class Test371两整数之和 {
    public static void main(String[] args) {
        Test371两整数之和 solution = new Test371两整数之和();
        System.out.println(solution.getSum(2, 3));
    }

    public int getSum(int a, int b) {
        int sum = 0;
        int carry = 0;
        while (true) {
            sum = a ^ b;
            carry = a & b;//进位
            if (carry == 0) {
                break;
            }
            a = sum;
            b = carry << 1;
        }
        return sum;
    }
}
